package parse_and_index;

import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Calendar;

public class Util {

	  public static String FILENAME_INDEX		= "index";
	  public static String DEFAULT_TXT_FILES_DIR = "/";
	  public static String DEFAULT_ENCODING	  = "latin1";

	  public static String now() {
			final String DATE_FORMAT_NOW = "yyyy-MM-dd HH:mm:ss";
			final Calendar cal = Calendar.getInstance();
			final SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT_NOW);
			return sdf.format(cal.getTime());
	  }

	  public static void printUsage() {
			System.err.println("Usage: java -jar invertedIndex.jar [OPTIONS] <Index file> [Text File]\n" + "  -build	<from doclist><index file>			Build new index from the documents listed in file <doclist>\n" + "  -search	<index file><output file><string>	Search index for string and store to output file\n" + "  -console										Send result to console instead of file\n");
			System.exit(1);
	  }

	  public static boolean validateString(final String toValidate) {
			return (toValidate != null) && !toValidate.equals("");
	  }

	  public static String[] cutFirstArgFromCmdLineArgs(final String[] args) {
			final String[] luceneArgs = new String[args.length - 1];
			for (int i = 1; i < args.length; i++) {
				  luceneArgs[i - 1] = args[i];
			}
			return luceneArgs;
	  }

	  public static boolean isValidPDFFilename(final String filename) {
			if (filename.contains(".pdf") || filename.contains(".PDF")) {
				  final File pdfFile = new File(filename);
				  if (pdfFile.exists()) { return true; }
			}
			return false;
	  }
}
